package org.jeecg.modules.lab.chemical.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hwpf.model.SectionDescriptor;
import org.jeecg.modules.lab.chemical.entity.ChemicalFactory;
import org.jeecg.modules.lab.chemical.entity.ChemicalName;
import org.jeecg.modules.lab.chemical.entity.ChemicalType;
import org.jeecg.modules.lab.chemical.entity.LabChemical;
import org.jeecg.modules.lab.chemical.mapper.LabChemicalMapper;
import org.jeecg.modules.lab.chemical.service.ILabChemicalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.security.auth.callback.LanguageCallback;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Description: 标物(化学品)信息管理表
 * @Author: jeecg-boot
 * @Date:   2023-08-15
 * @Version: V1.0
 */
@Service
@Slf4j
public class LabChemicalServiceImpl extends ServiceImpl<LabChemicalMapper, LabChemical> implements ILabChemicalService {

    @Autowired
    private LabChemicalMapper labChemicalMapper;

    //每天定时查询并判断状态
    @Override
    @Scheduled(cron = "0 0 1 * * ?")
    public void updateStatus() {
        log.info("定时查询标物状态");
        List<LabChemical> chemicalList = labChemicalMapper.selectList(new LambdaQueryWrapper<LabChemical>().eq(LabChemical::getStatus, "正常"));
        chemicalList.forEach(e->{
            if (e.getRestrictedDate().before(new Date())){
                //已过期
                labChemicalMapper.updateById(e.setStatus("已过期"));
            }
        });
    }

    @Override
    public List<ChemicalFactory> queryFactory() {
        List<ChemicalFactory> list=labChemicalMapper.queryFactory();
        return list;
    }

    @Override
    public List<ChemicalType> queryType() {
        List<ChemicalType> list=labChemicalMapper.queryType();
        return list;
    }

    @Override
    public List<ChemicalName> queryName() {
        List<ChemicalName> list=labChemicalMapper.queryName();
        return list;
    }
}
